home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 14 / CU Amiga Magazine's Super CD-ROM 14 (1997)(EMAP Images)(GB)(Track 1 of 3)[!][issue 1997-09].iso / CUCD / Programming / Asm_course / assembler course / 5.s < prev    next >
Encoding:
Text File  |  1989-09-01  |  2.0 KB  |  76 lines

  1. ; this source is a bit more complex. It does the following:
  2. ; left mousebutton: add 1 to the backgroundcolor (hardware register)
  3. ; right mousebutton: add 1 to the textcolor (also hardware register)
  4. ; if you press both buttons, the program will quit.
  5. ; we check the pressing of the buttons this way:
  6. ;    - move 0 to D0
  7. ;    - left button  ->  add 1 to D0
  8. ;    - right button ->  add 2 to D0
  9. ;    - now, if D0 is 0, no button was pressed
  10. ;    -      if D0 is 1, left button pressed
  11. ;    -      if D0 is 2, right MB pressed
  12. ;    -      if D0 is 3, both buttons pressed !!
  13. ; this may look complex, but think about it ! it's the simplest way!
  14. ; If a button is pressed or not can be seen in (again) some hardware
  15. ; registers. As you see: these addresses are pretty often used, and
  16. ; lists are indispendable !!
  17.  
  18. ; please note: this program adds 1 to the color each time it passes
  19. ; the loop. If you run the program, you can imagine the speed of 
  20. ; the processor... the colors are changed ca a million times/second
  21.  
  22. top:    movem.l    d0-d7/a0-a6,-(a7)    ; save regs
  23.  
  24. loop:
  25.     clr.l    d0            ; move zeros to d0
  26.  
  27. checkleft:
  28.  
  29.     btst    #6,$bfe001        ; check left button
  30.     bne.s    checkright        ; not pressed -> checkright
  31.  
  32.     add.l    #1,d0            ; pressed -> add 1 to d0
  33.  
  34. checkright:
  35.  
  36.     btst    #10,$dff016        ; this is how you check RMB
  37.     bne.s    selectaction        ; not pressed -> selectact.
  38.  
  39.     add.l    #2,d0            ; pressed -> add 2 to d0
  40.  
  41. selectaction:
  42.  
  43.     cmp.l    #1,d0            ; d0 = 1 ?
  44.     beq    backgroundflash        ; yes it is !!
  45.  
  46.     cmp.l    #2,d0            ; d0 = 2 ?
  47.     beq    textflash        ; yes it is !!
  48.  
  49.     cmp.l    #3,d0            ; d0 = 3 ?
  50.     beq    endofprogram        ; yes it is !!
  51.  
  52.     bra    loop            ; go back to LOOP
  53.  
  54. endofprogram:
  55.  
  56.     movem.l    (a7)+,d0-d7/a0-a6
  57.     rts
  58.  
  59. backgroundflash:
  60.  
  61.     add.w    #1,$dff180    ; the WORD at $dff180 contains the
  62.                 ; backgroundcolor (see lists)
  63.     bra    loop
  64.  
  65. textflash:
  66.  
  67.     add.w    #1,$dff182    ; the WORD at $dff182 contains the
  68.                 ; textcolor (see also list)
  69.     bra    loop
  70.  
  71.  
  72. ; this program is very badly written. In example 6, you'll see a
  73. ; good version of it, which is much more structured, and thus 
  74. ; much better readable.  You should try to be structured when
  75. ; you write a program.
  76.